Peterson's algorithm